home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PrtElmAc.cpp
-
- Contains: Implementation of class that handles accessing elements for
- the OpenDoc ContainerPart (formerly DrawPart)
-
- Owned by: Bennet Marks
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Based on: PrtPrpAc.cpp (owned by Nick Pilch)
-
- Change History (most recent first):
-
- <9> 9/18/95 JP 1285318: Made it cope with ODGetComments
- returning NULL
- <8> 9/11/95 JP 1269048 & 1283405: Use ODGet/SetComments
- <7> 9/4/95 TJ Added Includes to Compile with out
- PC-Headers.
- <6> 8/25/95 JP 1262410: Comments part to frame fallout
- <5> 8/11/95 jpa Removed duplicate MyAECoerceDescPtr
- [1276412]
- <4> 6/26/95 JBS &DMc&TÇ 1242642 BB: Refcounting Fixes.
- <3> 6/22/95 NP 1261960: draw part code to extract
- character for token accessed disposed
- memory.
- <2> 5/26/95 RR #1251403: Multithreading naming support
- <1> 4/26/95 BM first checked in
- <1> 04/13/95 BHM File first created
-
- To Do:
- */
- #ifndef _ALTPOINT_
- #include "AltPoint.h" // Use C++ savvy ODPoint and ODRect
- #endif
-
- #ifndef _PRTELMAC_
- #include "PrtElmAc.h"
- #endif
-
- #ifndef _DRWSHARED_
- #include "DrwShared.h"
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_Module_AppleTestDraw_defined
- #include "DrawPart.xh"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include "Facet.xh"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include "Frame.xh"
- #endif
-
- #ifndef SOM_ODPartWrapper_xh
- #include "PartWrap.xh"
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include "FrFaItr.xh"
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include "Trnsform.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h" // Adkins -- added
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #pragma segment PrtPrpEl
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- //==============================================================================
- // Local Classes
- //==============================================================================
-
- //==============================================================================
- // Global Variables
- //==============================================================================
-
- //==============================================================================
- // DrawPartElemAccessor
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::DrawPartElemAccessor
- //------------------------------------------------------------------------------
- DrawPartElemAccessor::DrawPartElemAccessor()
- {
- fElemClass = typeNull;
- fForm = typeNull;
- fSelectionData = kODNULL;
- fFrame = kODNULL;
- MAKE_DESC_NULL(fSelDataDesc);
- } //DrawPartElemAccessor
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::InitElemAccessor
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::InitElemAccessor(DescType elemClass, DescType form,
- AEDesc* selectionData, ODFrame* frame)
- {
- fElemClass = elemClass;
- fForm = form;
- fFrame = frame;
- fSelectionData = &fSelDataDesc;
- THROW_IF_ERROR( AEDuplicateDesc( selectionData, fSelectionData ) );
- } //InitElemAccessor
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::~DrawPartElemAccessor
- //------------------------------------------------------------------------------
- DrawPartElemAccessor::~DrawPartElemAccessor()
- {
- if DESC_IS_NOT_NULL( *GetSelectionData() ) AEDisposeDesc(fSelectionData);
- } //~DrawPartElemAccessor
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::GetData
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::GetData(AEDesc* result)
- {
- char returnChar;
-
- MAKE_DESC_NULL(*result);
-
- returnChar = GetOneChar();
-
- THROW_IF_ERROR( AECreateDesc( typeChar, &returnChar, 1, result ));
- } //GetData
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::SetData
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::SetData(AEDesc* data)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSLong index;
- Size actualSize;
- ODIText* iText = kODNULL;
- char* charPtr;
- char dataChar;
- ODError err = noErr;
-
- TRY
-
- if ( GetElemClass() != cChar ) THROW( errAEUnknownObjectType );
- if ( GetForm() != formAbsolutePosition ) THROW( errAEBadKeyForm );
-
- THROW_IF_ERROR( MyAECoerceDescPtr( *GetSelectionData(), typeLongInteger,
- (Ptr)&index, sizeof(index), &actualSize ) );
-
- if ( index < 1 ) THROW( errAENoSuchObject );
-
- ODFrame* frame = GetFrame();
-
- iText = ODGetComments( ev, frame, kODNULL );
-
- if ( !iText || index > GetITextStringLength(iText) ) THROW( errAENoSuchObject );
-
- charPtr = GetITextPtr(iText) + index - 1;
-
- THROW_IF_ERROR( MyAECoerceDescPtr( *data, typeChar,
- (Ptr)&dataChar, 1, &actualSize ) );
-
- if ( actualSize > 1 ) THROW(errAECoercionFail);
-
- *charPtr = dataChar;
-
- ODSetComments( ev, frame, iText );
-
- #if ODDebug
- GetFrame()->Invalidate(ev, (ODShape*)kODNULL, kODNULL);
- #endif
-
- CATCH_ALL
- err = ErrorCode();
- ENDTRY
-
- if (iText != kODNULL) DisposeIText(iText);
-
- THROW_IF_ERROR(err);
- } //SetData
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::GetOneChar
- //------------------------------------------------------------------------------
- char DrawPartElemAccessor::GetOneChar()
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSLong index;
- Size actualSize;
- ODIText* iText = kODNULL;
- char theChar;
- ODError error = noErr;
-
- TRY
- if ( GetElemClass() != cChar ) THROW( errAEUnknownObjectType );
- if ( GetForm() != formAbsolutePosition ) THROW( errAEBadKeyForm );
-
- THROW_IF_ERROR( MyAECoerceDescPtr( *GetSelectionData(), typeLongInteger,
- (Ptr)&index, sizeof(index), &actualSize ) );
-
- //NOTE: 1-based: first character has index = 1
-
- if ( index < 1 ) THROW( errAENoSuchObject );
-
- ODFrame* frame = GetFrame();
-
- iText = ODGetComments( ev, frame, kODNULL );
-
- if ( !iText || index > GetITextStringLength(iText) ) THROW( errAENoSuchObject );
-
- theChar = *(GetITextPtr(iText) + index - 1);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- if (iText != kODNULL) DisposeIText(iText);
-
- THROW_IF_ERROR(error);
-
- return theChar;
- } //GetOneChar
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::GetFrame
- //------------------------------------------------------------------------------
- ODFrame* DrawPartElemAccessor::GetFrame()
- {
- return fFrame;
- } //GetFrame
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::SetFrame
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::SetFrame(ODFrame* frame)
- {
- fFrame = frame;
- } //SetFrame
-
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::GetForm
- //------------------------------------------------------------------------------
- DescType DrawPartElemAccessor::GetForm()
- {
- return fForm;
- } //GetForm
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::SetForm
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::SetForm(DescType form)
- {
- fForm = form;
- } //SetForm
-
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::GetSelectionData
- //------------------------------------------------------------------------------
- AEDesc* DrawPartElemAccessor::GetSelectionData()
- {
- return fSelectionData;
- } //GetSelectionData
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::SetSelectionData
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::SetSelectionData(AEDesc* selectionData)
- {
- fSelectionData = selectionData;
- } //SetSelectionData
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::GetElemClass
- //------------------------------------------------------------------------------
- DescType DrawPartElemAccessor::GetElemClass()
- {
- return fElemClass;
- } //GetElemClass
-
- //------------------------------------------------------------------------------
- // DrawPartElemAccessor::SetElemClass
- //------------------------------------------------------------------------------
- void DrawPartElemAccessor::SetElemClass(DescType elemClass)
- {
- fElemClass = elemClass;
- } //SetElemClass
-
- //==============================================================================
- // Utility Functions
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // MyAECoerceDescPtr
- //------------------------------------------------------------------------------
- #if 0 /*Already defined in SEUtils.cpp*/
- ODError MyAECoerceDescPtr(
- AEDesc theAEDesc,
- DescType toType,
- Ptr dataPtr,
- Size maximumSize,
- Size* actualSize)
- {
- ODError error = noErr;
- AEDesc newDesc;
- AEDesc resultDesc;
- Size transferSize;
-
- MAKE_DESC_NULL(resultDesc);
-
- TRY
- {
- if ((toType == theAEDesc.descriptorType) || (toType == typeWildCard))
- newDesc = theAEDesc; //no need to coerce
- else
- {//must coerce desc
- THROW_IF_ERROR( AECoerceDesc(&theAEDesc,toType,&resultDesc) );
- newDesc = resultDesc;
- }
-
- //special case for NIL handle - **CHECK what we should really do
- if (newDesc.dataHandle == kODNULL) actualSize = 0;
- else
- {//not a NIL handle
- *actualSize = GetHandleSize(newDesc.dataHandle);
- THROW_IF_ERROR(MemError());
-
- transferSize = *actualSize;
- if (maximumSize < transferSize) transferSize = maximumSize;
-
- BlockMove(*(newDesc.dataHandle), dataPtr, transferSize);
- };
- }
-
- CATCH_ALL
- {
- error = ErrorCode();
- }
- ENDTRY
-
- if DESC_IS_NOT_NULL(resultDesc) AEDisposeDesc(&resultDesc);
-
- return error;
- } //MyAECoerceDescPtr
- #endif
-
- //------------------------------------------------------------------------------
- // GetOneCharFromDesc
- //------------------------------------------------------------------------------
- char GetOneCharFromDesc(AEDesc* charDesc)
- {
- char resultChar;
- Size actualSize;
-
- THROW_IF_ERROR( MyAECoerceDescPtr( *charDesc, typeChar, &resultChar,
- 1, &actualSize ) );
-
- if ( actualSize > 1 ) THROW(errAECoercionFail);
-
- return resultChar;
- }
-